home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch2 / FillMode.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-03-23  |  8.1 KB  |  235 lines

  1. VERSION 5.00
  2. Begin VB.Form frmFillMode 
  3.    Caption         =   "FillMode"
  4.    ClientHeight    =   4470
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6720
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4470
  10.    ScaleWidth      =   6720
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.PictureBox picBothAlternateCW 
  13.       AutoRedraw      =   -1  'True
  14.       FillColor       =   &H00FFFFFF&
  15.       FillStyle       =   0  'Solid
  16.       Height          =   1935
  17.       Left            =   4560
  18.       ScaleHeight     =   125
  19.       ScaleMode       =   3  'Pixel
  20.       ScaleWidth      =   139
  21.       TabIndex        =   6
  22.       Top             =   480
  23.       Width           =   2145
  24.    End
  25.    Begin VB.PictureBox picBothWindingCW 
  26.       AutoRedraw      =   -1  'True
  27.       FillColor       =   &H00FFFFFF&
  28.       FillStyle       =   0  'Solid
  29.       Height          =   1935
  30.       Left            =   4560
  31.       ScaleHeight     =   125
  32.       ScaleMode       =   3  'Pixel
  33.       ScaleWidth      =   139
  34.       TabIndex        =   5
  35.       Top             =   2520
  36.       Width           =   2145
  37.    End
  38.    Begin VB.PictureBox picBothAlternate 
  39.       AutoRedraw      =   -1  'True
  40.       FillColor       =   &H00FFFFFF&
  41.       FillStyle       =   0  'Solid
  42.       Height          =   1935
  43.       Left            =   2400
  44.       ScaleHeight     =   125
  45.       ScaleMode       =   3  'Pixel
  46.       ScaleWidth      =   139
  47.       TabIndex        =   3
  48.       Top             =   480
  49.       Width           =   2145
  50.    End
  51.    Begin VB.PictureBox picBothWinding 
  52.       AutoRedraw      =   -1  'True
  53.       FillColor       =   &H00FFFFFF&
  54.       FillStyle       =   0  'Solid
  55.       Height          =   1935
  56.       Left            =   2400
  57.       ScaleHeight     =   125
  58.       ScaleMode       =   3  'Pixel
  59.       ScaleWidth      =   139
  60.       TabIndex        =   2
  61.       Top             =   2520
  62.       Width           =   2145
  63.    End
  64.    Begin VB.PictureBox picStarWinding 
  65.       AutoRedraw      =   -1  'True
  66.       FillColor       =   &H00FFFFFF&
  67.       FillStyle       =   0  'Solid
  68.       Height          =   1935
  69.       Left            =   240
  70.       ScaleHeight     =   125
  71.       ScaleMode       =   3  'Pixel
  72.       ScaleWidth      =   139
  73.       TabIndex        =   1
  74.       Top             =   2520
  75.       Width           =   2145
  76.    End
  77.    Begin VB.PictureBox picStarAlternate 
  78.       AutoRedraw      =   -1  'True
  79.       FillColor       =   &H00FFFFFF&
  80.       FillStyle       =   0  'Solid
  81.       Height          =   1935
  82.       Left            =   240
  83.       ScaleHeight     =   125
  84.       ScaleMode       =   3  'Pixel
  85.       ScaleWidth      =   139
  86.       TabIndex        =   0
  87.       Top             =   480
  88.       Width           =   2145
  89.    End
  90.    Begin VB.Label Label1 
  91.       Alignment       =   2  'Center
  92.       Caption         =   "Star Counterclockwise"
  93.       Height          =   255
  94.       Index           =   2
  95.       Left            =   4560
  96.       TabIndex        =   9
  97.       Top             =   0
  98.       Width           =   2175
  99.    End
  100.    Begin VB.Label Label1 
  101.       Alignment       =   2  'Center
  102.       Caption         =   "Star Counterclockwise"
  103.       Height          =   255
  104.       Index           =   0
  105.       Left            =   240
  106.       TabIndex        =   8
  107.       Top             =   0
  108.       Width           =   2175
  109.    End
  110.    Begin VB.Label Label1 
  111.       Alignment       =   2  'Center
  112.       Caption         =   "Rectangle Clockwise"
  113.       Height          =   255
  114.       Index           =   3
  115.       Left            =   4560
  116.       TabIndex        =   7
  117.       Top             =   240
  118.       Width           =   2175
  119.    End
  120.    Begin VB.Label Label1 
  121.       Alignment       =   2  'Center
  122.       Caption         =   "Star Counterclockwise"
  123.       Height          =   255
  124.       Index           =   1
  125.       Left            =   2400
  126.       TabIndex        =   4
  127.       Top             =   0
  128.       Width           =   2175
  129.    End
  130. Attribute VB_Name = "frmFillMode"
  131. Attribute VB_GlobalNameSpace = False
  132. Attribute VB_Creatable = False
  133. Attribute VB_PredeclaredId = True
  134. Attribute VB_Exposed = False
  135. Option Explicit
  136. Private Type POINTAPI
  137.     x As Long
  138.     y As Long
  139. End Type
  140. Private Declare Function PolyPolygon Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long) As Long
  141. Private Declare Function SetPolyFillMode Lib "gdi32" (ByVal hdc As Long, ByVal nPolyFillMode As Long) As Long
  142. Private Const ALTERNATE = 1
  143. Private Const WINDING = 2
  144. Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W2 As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
  145. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  146. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  147. Private Const FW_BOLD = 700
  148. Private Const ANSI_CHARSET = 0
  149. Private Const OUT_DEFAULT_PRECIS = 0
  150. Private Const CLIP_CHARACTER_PRECIS = 1
  151. Private Const CLIP_LH_ANGLES = 16
  152. Private Const PROOF_QUALITY = 2
  153. Private Const VARIABLE_PITCH = 2
  154. Private Const FF_ROMAN = 16
  155. Private Sub DrawLabels()
  156. Dim new_font As Long
  157. Dim old_font As Long
  158. Dim wid As Single
  159. Dim hgt As Single
  160.     AutoRedraw = True
  161.     ScaleMode = vbPixels
  162.     ' Create the rotated font.
  163.     new_font = CreateFont(12, 0, 900, 900, _
  164.         FW_BOLD, False, False, False, _
  165.         ANSI_CHARSET, OUT_DEFAULT_PRECIS, _
  166.         CLIP_LH_ANGLES Or CLIP_CHARACTER_PRECIS, _
  167.         PROOF_QUALITY, 0, "Arial")
  168.     SelectObject hdc, new_font
  169.     hgt = TextWidth("ALTERNATE")
  170.     CurrentX = 0
  171.     CurrentY = picStarAlternate.Top + _
  172.         (picStarAlternate.Height + hgt) / 2
  173.     Print "ALTERNATE"
  174.     hgt = TextWidth("WINDING")
  175.     CurrentX = 0
  176.     CurrentY = picStarWinding.Top + _
  177.         (picStarWinding.Height + hgt) / 2
  178.     Print "WINDING"
  179.     SelectObject hdc, old_font
  180.     DeleteObject new_font
  181. End Sub
  182. ' Initialize the point data.
  183. Private Sub InitializeData(pt() As POINTAPI, num_pts() As Long)
  184.     ' Counterclockwise star.
  185.     pt(1).x = 72:  pt(1).y = 3
  186.     pt(2).x = 8:   pt(2).y = 119
  187.     pt(3).x = 133: pt(3).y = 24
  188.     pt(4).x = 16:  pt(4).y = 37
  189.     pt(5).x = 120: pt(5).y = 108
  190.     num_pts(1) = 5
  191.     ' Counterclockwise rectangle.
  192.     pt(6).x = 43:  pt(6).y = 110
  193.     pt(7).x = 108: pt(7).y = 110
  194.     pt(8).x = 108: pt(8).y = 16
  195.     pt(9).x = 43:  pt(9).y = 16
  196.     num_pts(2) = 4
  197. End Sub
  198. ' Make the rectangle's points clockwise.
  199. Private Sub ReverseRectangle(pt() As POINTAPI, num_pts() As Long)
  200.     ' Clockwise rectangle.
  201.     pt(6).x = 43:  pt(6).y = 16
  202.     pt(7).x = 108: pt(7).y = 16
  203.     pt(8).x = 108: pt(8).y = 110
  204.     pt(9).x = 43:  pt(9).y = 110
  205.     num_pts(2) = 4
  206. End Sub
  207. Private Sub Form_Load()
  208. Dim pt(1 To 100) As POINTAPI
  209. Dim num_pts(1 To 2) As Long
  210.     ' Initialize the data.
  211.     InitializeData pt, num_pts
  212.     ' Draw just the star with fill style ALTERNATE.
  213.     SetPolyFillMode picStarAlternate.hdc, ALTERNATE
  214.     PolyPolygon picStarAlternate.hdc, pt(1), num_pts(1), 1
  215.     ' Draw just the star with fill style WINDING.
  216.     SetPolyFillMode picStarWinding.hdc, WINDING
  217.     PolyPolygon picStarWinding.hdc, pt(1), num_pts(1), 1
  218.     ' Draw both shapes with fill style ALTERNATE.
  219.     SetPolyFillMode picBothAlternate.hdc, ALTERNATE
  220.     PolyPolygon picBothAlternate.hdc, pt(1), num_pts(1), 2
  221.     ' Draw both shapes with fill style WINDING.
  222.     SetPolyFillMode picBothWinding.hdc, WINDING
  223.     PolyPolygon picBothWinding.hdc, pt(1), num_pts(1), 2
  224.     ' Make the rectangle clockwise.
  225.     ReverseRectangle pt, num_pts
  226.     ' Draw both shapes with fill style ALTERNATE.
  227.     SetPolyFillMode picBothAlternateCW.hdc, ALTERNATE
  228.     PolyPolygon picBothAlternateCW.hdc, pt(1), num_pts(1), 2
  229.     ' Draw both shapes with fill style WINDING.
  230.     SetPolyFillMode picBothWindingCW.hdc, WINDING
  231.     PolyPolygon picBothWindingCW.hdc, pt(1), num_pts(1), 2
  232.     ' Draw the ALTERNATE and WINDING labels.
  233.     DrawLabels
  234. End Sub
  235.